home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
228_01
/
cwindemo.doc
< prev
next >
Wrap
Text File
|
1987-07-29
|
25KB
|
658 lines
C-window Demonstration Copyright (C) 1983 by c-systems
C-window Demonstration Document File
------------------------------------
Do it NOW!
----------
This file shows how to use the c-window DEMO provided in
Diskette B.
Print this file and the file "dump.c" (also on Diskette B),
as constant reference will be made to them in this document.
Overview
--------
C-window(tm) is used to debug C programs at the source-code
level. C-window provides an interactive debugging
environment that simplifies the program development process.
C-window commands can:
o set breakpoints at a function name and
source-code line,
o single step and trace at the C
source-statement level,
o display the value of variables, using the
same variable names as used in the C source
code (Local and external are supported),
o display the source code of the program
under test,
o display complex expressions, like the third
element of an array of characters, which is
a member of a structure, which is an
element in an array of structures, and
o override minor program bugs allowing more
of the program to be tested before a
recompilation is needed.
To use the c-window debugger, the source code must be
compiled using the "-w" option of the c-systems C compiler.
During the link step the object code library, c-window.lib,
is included, which embeds the c-window executive into the
executable object file. When the final test module is
invoked, the c-window executive is actually given control,
not the program being tested.
The Programs Dump.C and Dump.Exe
--------------------------------
Dump.c is the source code for a dump utility that dumps an
ASCII file in both hex. and ASCII format, while showing the
address of the data in the file. The executable module,
"dump.exe" is also contained on Diskette B.
To study the output of this program, type:
A>dump dump.c
(For the purposes of this DEMO package we assume that all
files mentioned are available on drive A.)
The program reads the input file dump.c and displays three
fields on the monitor. The leftmost field contains the
starting address of the data displayed. The middle field
contains the hex. representation of the file, and the
rightmost field contains the ASCII representation of the
hex. data. Periods are displayed in the rightmost field to
represent extended-ASCII characters.
C-window Demonstration Program
------------------------------
I suggest that you review the "dump.c" source code before
proceeding with this DEMO.
The DEMO program,"cwdump.exe", is also contained on Diskette
B. Assuming it is on drive A, type
A>cwdump dump.c
to start the DEMO.
If you are using an IBM-PC or compatible, the screen is
divided into three sections. These sections are treated as
independent windows by the c-window executive. The top
window is the debugger interface. All commands issued and
responses received are displayed within the top window. The
middle window is dedicated to the application keyboard input
and screen output. The hex. dump that you saw when you ran
"dump.exe" will appear only within this window. The last
window, at the bottom of the screen, displays the source
code of the file being debugged. Whenever a single step, a
trace, or a breakpoint occurs the last window is updated to
show the results of the instruction. This allows for
debugging at the source level without the need to reprint
the source code each time a source code change is made.
When the program begins execution a message is issued
indicating the function name ("main") and the line number
where execution begins. The message
entry at main line 22
>>
should appear in the top window, showing that execution of
the program under test started in the function named "main"
at line 22. The ">>" is the c-window command-line prompt and
indicates that c-window is waiting for a command. C-window's
response to your command is not preceded by the ">>' prompt,
so you can easily tell them apart.
To exit the DEMO, type "ex" after the ">>' prompt displayed
in the top window.
As our first command to the debugger, let's display the
arguments passed into the "main" function (i.e. argc and
argv). The command
>>d argc
2
displays the number of parameters typed on the command line
when the program was invoked. The "2" shown on the next line
is c-window's response to this command.
To display the parameter entered on the command line, type:
>>ds argv[1]
dump.c
The <ds> command tells c-window to display "argv[1]" using
the string format, and indeed C-window's response to the
command matches the command-line entry used to invoke
"cwdump.exe"
We saw earlier that "argc" was equal to 2. On line 22 of
"dump.c" an "if" statement checks to see if "argc" is less
than 2. Since "argc" is not less than 2, we expect that
lines 23, 24, and 25 (the body of the "if" statement) will
be skipped and execution resumed at line 26, the first
statement after the "if" statement. C-window`s single step
command is used below. Let's see what happens.
>>s
step at main line 26
Sure enough. The body of the "if" statement was skipped and
line 26 will be executed next.
The "if" statement on line 26 tries to open the file named
in argv[1] ("dump.c") and then checks the value returned by
"fopen" to see if any errors were detected. Let's single
step again and look at the results.
>>s
step at main line 30
C-window's response shows that no errors were detected since
line 27 and 28 were skipped. The pointer "infp" now holds
the file pointer that will be used for all subsequent file
operations on "dump.c".
The "if" statement on line 30 checks if an output file name
was entered on the command line of "cwdump" and also checks
that the output file is not the same file as the input file.
>>s
step at main line 37
As no output file was typed on the command line when
"cwdump.exe" was executed "argc" is not greater than 2. So
lines 31, 32, and 33 were skipped, and line 37 is the next
line to be executed. Line 37 assigns the console to the
output file pointer so subsequent output done by the program
will go to the console screen.
Now let's set a non-sticky breakpoint using the <g> command.
(go command). This breakpoint will be set at line 40 of
function "main". This line follows the code that reads the
first 16 bytes of "dump.c".
>>g main,40
break at main line 40
Execution begins at the current location and stops when line
40 in "main" is to be executed. C-window's response shows
where the breakpoint occurred. The number of elements
actually read from the file, in "nread", can be displayed
using the command:
>>d nread
10
The <d> command indicates to display the variable "nread" in
hex. format (Any C expression can be displayed, not just
simple variables.) So "nread" = 0x10 or 16 decimal. Notice
that you typed "nread", the same name declared in the source
code. This is symbolic debugging. The value of "nread" shows
that 16 bytes were read from "dump.c"
Alternately, to display the contents of "nread" in decimal,
use:
>>dd nread
16
Let's look at the data that was read from "dump.c". Since we
know that this data was placed into a buffer with address
"buf", to display the data in a byte-fo